<extend name="layout/main" />

<block name="HEADER">
	<style type="text/css">
		.iconfont.stars{ padding: 0 3px; line-height: 1; color: #e4e4e4; }
        .iconfont.yellow{ color: #ffa500; }
        .xw__grid .layui-table-view .layui-table td .layui-table-cell .link{ margin: 0 3px; }
	</style>
</block>

<block name="CONTENT">
	<div class="wrapper">
		<div class="panel-heading">
			<control:search id="searchs" />
		</div>
		<div class="content">
			<div style="height: 100%;display: flex;">
				<control:grid id="grid" padding="0" height="100%" style="width:calc(50% - 5px);"/>
				<div style="width: 10px;"></div>
				<control:grid id="grid2" padding="0" height="100%" style="width:calc(50% - 5px);"/>
			</div>
		</div>
	</div>
</block>

<block name="FOOTER">
	<script type="text/javascript">
		var page = (function(ns){
            //页面初始化
            ns.init=function(){
                ns.query();
            }
            
            //搜索事件
            ns.query=function(){
                grid.load( searchs.getData() );
            }
            
            //行单击
            ns.rowClick = function(){
                var row = grid.getSelectedRows()[0];
                grid2.load([{opera: "=", field: "pid", value: row.id }]);
            }
            
            //新增
            ns.add=function(type){
                var row = grid.getSelectedRows()[0];
                if(type==2 && !row){
                    $.toast(0,"请先选择一级菜单！");
                    return;
                }
                if(type==2 && row.type != "多级菜单类型" ){
                    $.toast(0,"不是多级菜单类型，不允许新增子菜单！");
                    return;
                }
                var filter = {
                    url:"wechat/menu/edit",
                    oid:"",
                    mode:1,
                    type:type,
                    pid: type==2 ? grid.getSelectedRows()[0].id : 0,
                }
                $.openIframe(filter, "编辑",['535px', '420px']); 
            }
            
            //编辑
            ns.edit=function(type){
                var selectedRow = (type == 2 ? grid2 : grid).getSelectedRows()[0];
                var filter = {
                    url:"wechat/menu/edit",
                    oid: selectedRow.id ,
                    mode:2,
                    type:type,
                }
                $.openIframe(filter, "编辑",['535px', '420px']); 
            }  
            
            //删除
            ns.del =function(id,type){
                (type == 2 ? grid2 : grid).deleteSelectRow(true);
            }
            
            //下拉移动  type: 1 = 上移 ,  type: 2 = 下移
            ns.move = function(mode,type){
                (type == 2 ? grid2 : grid).adjustSort(mode,"sort_no");
            }
            
            //启用与禁用
            //mode=0 等于禁用
            ns.enableAndStand=function(isEnable,type){
                var selectedRow = (type == 2 ? grid2 : grid).getSelectedRows()[0];
                if(!selectedRow){
                    $.toast(0,"请先选择数据！");
                    return;
                }
                $.confirm( ( isEnable != "启用" ? "确认启用？" : "确认禁用？"),function(index){
                    grid.updateField(selectedRow.id,"is_enable",isEnable == '启用' ? '禁用' : '启用');
                    layer.close(index);
                });
            }
            
            return ns;
        }({}));
        
        
        $(function(){ page.init();  });
	</script>
</block>